local guanshi = fk.CreateSkill {
  name = "lvshi__guanshi",
}

Fk:loadTranslationTable{
  ["lvshi__guanshi"] = "仁忌",
  [":lvshi__guanshi"] = "当一名角色的手牌数变为全场最多后，你可摸一张牌，然后若你的手牌数为场上最多，你失去“仁忌”并于轮次结束后获得“威服”。",
  ["$lvshi__guanshi1"] = "稳据江汉，坐观时变。",
  ["$lvshi__guanshi2"] = "愿行仁义之道，何愁人心不归。",
}

-- 观势技能实现
guanshi:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(guanshi.name) then return end
    local room = player.room
     -- 检查是否有角色的手牌数变为全场最多
    for _, move in ipairs(data) do
      if move.to and move.toArea == Card.PlayerHand and move.skillName ~= guanshi.name then
        local max_handcard_count = 0
        for _, p in ipairs(room:getAlivePlayers()) do
          max_handcard_count = math.max(max_handcard_count, p:getHandcardNum())
        end
        return move.to:getHandcardNum() >= max_handcard_count
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, guanshi.name)
    local max_handcard_count = 0
    for _, p in ipairs(room:getAlivePlayers()) do
      max_handcard_count = math.max(max_handcard_count, p:getHandcardNum())
    end
    if player:getHandcardNum() >= max_handcard_count then
      room:handleAddLoseSkills(player, "-lvshi__guanshi")
      room.logic:getCurrentEvent():findParent(GameEvent.Round, true, Player.HistoryGame):addCleaner(function ()
        room:handleAddLoseSkills(player, "lvshi__weifu")
      end)
    end
  end,
})

return guanshi